home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 6
/
FM Towns Free Software Collection 6.iso
/
t_os
/
book
/
src
/
snd.c
< prev
next >
Wrap
Text File
|
1993-07-08
|
2KB
|
82 lines
#include <stdio.h>
#include <stdlib.h>
#include <mos.h>
#include <string.h>
#include <egb.h>
#include <sugi.h>
#include "book.h"
#include "lib.h"
#include "keyio.h"
#include "snd.h"
#include "mouse.h"
int snd_play( char *file )
{
static long bufsiz = 0 ;
static char *buf = NULL ;
static char *lastfile = NULL ;
FILE *fp ;
int sw, status = FALSE ;
long fsize ;
SND_pcm_sound_delete( -1 ) ;
SND_pcm_mode_set( 1 ) ;
if( lastfile != NULL && strcmp( lastfile, file ) == 0 && buf != NULL )
status = TRUE ;
else
{
if( lastfile != NULL )
free( lastfile ), lastfile = NULL ;
if( ( fp = fopen( file, "rb" ) ) == NULL )
return ERR ;
if( ( fsize = get_fsize( fp ) ) > bufsiz )
{
bufsiz = fsize ;
if( buf != NULL )
free( buf ), buf = NULL ;
}
if( buf == NULL )
buf = malloc( bufsiz ) ;
if( buf != NULL )
if( fread( buf, 1, fsize, fp ) == fsize )
if( *(int *)(buf+12) <= fsize-32 )
{
lastfile = strdup( file ) ;
status = TRUE ;
}
fclose( fp ) ;
if( status == FALSE )
return ERR ;
}
SND_pan_set( 71, 64 ) ;
*(int *)(buf+20) = 0 ;
SND_pcm_play2( 71, buf[28], 127, buf ) ;
for( status = ERR+1 ; SND_pcm_status( 71 ) ; )
{
mos_rdpos(&sw, NULL,NULL);
if (sw != 0 || kbhit())
{
while (sw != 0)
mos_rdpos(&sw, NULL,NULL);
keyflush();
status = ERR;
break;
}
}
SND_pcm_play_stop( 71 ) ;
SND_pcm_rec_stop() ;
return status ;
}